<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="paperNumber">
        <el-input
          v-model="queryParams.paperNumber"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="cellPhoneNumber">
        <el-input
          v-model="queryParams.cellPhoneNumber"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appUserList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="头像" align="center" prop="headPortrait" width="80">
        <template slot-scope="scope">
          <el-avatar shape="square" size="small" :src="scope.row.headPortrait"></el-avatar>
        </template>
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickname" />
      <el-table-column label="性别" align="center" prop="gender" :formatter="sexFormat" />
      <el-table-column label="出生日期" align="center" prop="birthday" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号码" align="center" prop="cellPhoneNumber" />
      <el-table-column label="职业" align="center" prop="occupation" />
      <el-table-column label="证件类型" align="center" prop="paperType" :formatter="paperTypeFormat" />
      <el-table-column label="证件号码" align="center" prop="paperNumber" />
      <el-table-column label="openId" align="center" prop="openId" />
      <!--<el-table-column label="账号" align="center" prop="account" />-->
      <!--<el-table-column label="密码" align="center" prop="password" />-->
      <el-table-column label="个性签名" align="center" prop="personalSignature" show-overflow-tooltip/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAppUser,exportAppUser } from "@/api/phone/appUser";

export default {
  name: "AppUser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // app用户表格数据
      appUserList: [],
      // 性别字典
      sexOptions: [],
      // 证件类型字典
      paperTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paperNumber: null,
        cellPhoneNumber: null,
        nickname:null
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("paper_type").then(response => {
      this.paperTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询app用户列表 */
    getList() {
      this.loading = true;
      listAppUser(this.queryParams).then(response => {
        this.appUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.gender);
    },
    // 证件类型字典翻译
    paperTypeFormat(row, column) {
      return this.selectDictLabel(this.paperTypeOptions, row.paperType);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.appUserId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有app用户数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAppUser(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
